package org.lanqiao.music.common.utils;

import com.github.pagehelper.PageInfo;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * 分页响应结构体
 *
 * @author Ray
 * @since 2022/2/18
 */
@Data
public class PageHelperResult<T> implements Serializable {

    private String code;

    private Data<T> data;

    private String msg;

    public static <T> PageHelperResult<T> success(PageInfo page) {
        PageHelperResult<T> result = new PageHelperResult<>();
        result.setCode(ResultCode.SUCCESS.getCode());

        Data data = new Data<T>();
        data.setList(page.getList());
        data.setTotal(page.getTotal());

        result.setData(data);
        result.setMsg(ResultCode.SUCCESS.getMsg());
        return result;
    }

    @lombok.Data
    public static class Data<T> {

        private List<T> list;

        private long total;

    }

}
